package com.mustafaiev.tair.autobase.web.command;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

/**
 * The Command class implements {@link AutobaseServletCommand} and provides
 * logout
 * 
 * @author Tair Mustafaiev
 * 
 */
public class LogoutCommandImpl implements AutobaseServletCommand {

    private static final Logger LOG = Logger.getLogger(LogoutCommandImpl.class.getName());

    @Override
    public void processGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        LOG.info("Session was destroyed ");
        req.getSession(true).removeAttribute(SESS_AUTH);
        req.getSession(true).invalidate();
        resp.sendRedirect("/");

    }

    @Override
    public void processPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        // nothing to do here...
        new NotImplementedException();
    }

}
